@extends('backend.layouts.app')

@section('content')
<div class="layui-card">
    <div class="layui-card-header layui-card-header-auto">
        @if($type=='init')
        初始化密码
        @elseif($type=='change')
        修改密码
        @endif
    </div>
    <div class="layui-card-body">
        <form class="layui-form" action="{{route('admin.auth.manager.password.change',['id'=>$id, 'type'=>$type])}}"
            method="POST">
            {{method_field('put')}}
            @csrf
            @if($type=='change')
            <div class="layui-form-item">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-block">
                    <input type="password" class="layui-input" name="old_pass" lay-verify="required" value="">
                </div>
            </div>
            @endif
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input id="new_pass" type="password" class="layui-input" name="new_pass" lay-verify="required" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-block">
                    <input type="password" class="layui-input" name="make_pass" lay-verify="makePass" value="">
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">确 认</button>
                    <a class="layui-btn" href="{{route('admin.auth.manager.index')}}">返 回</a>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection

@section('script')
<script type="text/javascript">
    layui.use(['form'], function () {
        let form = layui.form;
        //自定义验证规则
        form.verify({
            makePass: function(value,){
                var new_pass = $('#new_pass').val();
                if(!value){
                    return '确认密码不能为空';
                }
                if(value !== new_pass){
                    return '新密码与确认密码不一致'
                }
            }
        });
    });
</script>
@endsection
